import axios from "axios"
import jsonp from "common/js/jsonp"
import {commonParams, options} from "./config"

// 获取热门搜索词
export function getHotKey() {
    const url = 'https://c.y.qq.com/splcloud/fcgi-bin/gethotkey.fcg'

    const data = Object.assign({}, commonParams, {
        platform: 'h5',
        needNewCode: 1
    })

    return jsonp(url, data, options)
}

// 通过query搜索歌手或歌曲
export function getSearchSongList(query, page, perpage) {
    let date = new Date().getTime()
    const url = 'api/search'

    return axios(url, {
        params: {
            g_tk: 5381,
            w: query,
            p: page,
            uin: 0,
            format: 'json',
            inCharset: 'utf-8',
            outCharset: 'utf-8',
            notice: 0,
            platform: 'yqq.json',
            needNewCode: 1,
            zhidaqu: 1,
            catZhida: 1,
            t: 0,
            flag: 1,
            ie: 'utf-8',
            sem: 1,
            aggr: 0,
            perpage,
            n: perpage,
            remoteplace: 'txt.mqq.all',
            _: date
        }
    }).then((res) => {
        return res
    })

    // const data = Object.assign({}, commonParams, {
    //     w: query,
    //     p: page,
    //     catZhida: zhida ? 1 : 0,
    //     zhidaqu: 1,
    //     t: 0,
    //     flag: 1,
    //     ie: 'utf-8',
    //     sem: 1,
    //     aggr: 0,
    //     perpage: 20,
    //     n: 20,
    //     remoteplace: 'txt.mgg.all',
    //     uin: 0,
    //     needNewCode: 1,
    //     platform: 'h5'
    // })

    // return jsonp(url, data, options)
}